package com.bw.service.impl;

import com.bw.dao.RoleDao;
import com.bw.dao.impl.RoleDaoImpl;
import com.bw.pojo.Role;
import com.bw.service.RoleService;
import com.bw.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class RoleServiceImpl implements RoleService {
    private SqlSessionFactory sqlSessionFactory = MyBatisUtil.getSqlSessionFactory();
    //查看
    @Override
    public List<Role> getRoleList(Role role) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        RoleDao roleMapper = sqlSession.getMapper(RoleDao.class);
        List<Role> list = roleMapper.getRoleList(role);
        sqlSession.close();
        return list;
    }
    //添加
    @Override
    public void addGet(Role role) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        RoleDao roleMapper = sqlSession.getMapper(RoleDao.class);
        roleMapper.addGet(role);
        sqlSession.commit();
        sqlSession.close();
    }
    //删除
    @Override
    public void getToDel(String uids) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        RoleDao roleMapper = sqlSession.getMapper(RoleDao.class);
        roleMapper.getToDel(uids);
        sqlSession.commit();
        sqlSession.close();
    }
    //回显
    @Override
    public Role findByIn(Integer id) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        RoleDao roleMapper = sqlSession.getMapper(RoleDao.class);
        Role role = roleMapper.findByIn(id);
        sqlSession.close();
        return role;
    }
    //修改
    @Override
    public void getUpd(Role role) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        RoleDao roleMapper = sqlSession.getMapper(RoleDao.class);
        roleMapper.getUpd(role);
        sqlSession.commit();
        sqlSession.close();
    }


}
